package com.dys.config;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

/**
 * @className: com.dys.config.GlobalExceptionHandler2
 * @description: 自定义的HandlerExceptionResolver
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/11/01 21:53
 */
@Configuration
public class GlobalExceptionHandler2 implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        ModelAndView mv = new ModelAndView();
        if (ex instanceof ArithmeticException) {
            mv.setViewName("err2.jsp");
        }
        if (ex instanceof NullPointerException) {
            mv.setViewName("err3.jsp");
        }
        mv.addObject("msg", ex.getMessage());
        return mv;
    }
}
